package org.jfteam.common.domain;

import java.io.Serializable;

/**
 * created with IntelliJ IDEA.
 * description: 分页请求参数
 * author:      fengwenping
 * date:        2019/7/14 19:34
 */
public class PageRequest implements Pageable, Serializable {

    private final int page;
    private final int size;
    private Sort sort;

    public PageRequest(int page, int size) {
        if (page < 0) {
            throw new IllegalArgumentException("Page index must not be less than zero!");
        }
        if (size < 1) {
            throw new IllegalArgumentException("Page size must not be less than one!");
        }
        this.page = page;
        this.size = size;
    }

    public PageRequest(int page, int size, Sort.Direction direction, String... properties) {
        this(page, size, new Sort(direction, properties));
    }

    public PageRequest(int page, int size, Sort sort) {
        this(page, size);
        this.sort = sort;
    }

    @Override
    public int getPageSize() {
        return size;
    }

    @Override
    public int getPageNumber() {
        return page;
    }

    @Override
    public Sort getSort() {
        return sort;
    }

    @Override
    public Object getEntity() {
        return null;
    }
}
